package com.hongning.railway.ui.main.fragments.dynamic.itemviewmodel;

import android.databinding.ObservableField;
import android.databinding.ObservableList;
import android.os.Bundle;
import android.support.annotation.NonNull;

import com.hongning.railway.app.Constant;
import com.hongning.railway.entity.DynamicEntity;
import com.hongning.railway.entity.resbean.ResDynamicBean;
import com.hongning.railway.ui.dynamic_photo.DynamicPhotoFragment;
import com.hongning.railway.ui.main.fragments.dynamic.DynamicViewModel;

import me.goldze.mvvmhabit.base.BaseViewModel;
import me.goldze.mvvmhabit.base.MultiItemViewModel;
import me.goldze.mvvmhabit.binding.command.BindingAction;
import me.goldze.mvvmhabit.binding.command.BindingCommand;
import me.goldze.mvvmhabit.utils.ToastUtils;

public class Type1ItemViewModel extends MultiItemViewModel<DynamicViewModel> {
    public ObservableField<ResDynamicBean.DataBean> type1data=new ObservableField<>();
    public ObservableField<String> picnum = new ObservableField<>();
    public ObservableField<Boolean> isSelected = new ObservableField<>(false);
    public ObservableField<String> praisenum = new ObservableField<>();
    public BindingCommand itemClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            Bundle bundle = new Bundle();
            bundle.putParcelable(Constant.EXTRA_DATA,type1data.get());
            viewModel.startContainerActivity(DynamicPhotoFragment.class.getCanonicalName(),bundle);
        }
    });

    public BindingCommand praiseClick = new BindingCommand(new BindingAction() {
        @Override
        public void call() {
            if (isSelected.get()){
                ToastUtils.showShort("您已经点过赞了");
                return;
            }
            isSelected.set(true);
            int current = Integer.parseInt(type1data.get().getExt1())+1;
            praisenum.set(String.valueOf(current));
            type1data.set(type1data.get());
            viewModel.clickPraise(type1data.get().getNewsId(),"1");
        }
    });
    public Type1ItemViewModel(@NonNull DynamicViewModel viewModel, ResDynamicBean.DataBean data) {
        super(viewModel);
        type1data.set(data);
        praisenum.set(data.getExt1());
        if ("1".equals(data.getExt2())){
            isSelected.set(true);
        }else {
            isSelected.set(false);
        }
        picnum.set("共"+data.getExt3()+"张");
    }

    @Override
    public Integer getItemType() {
        return type1data.get().getType();
    }
}
